import type {DataResponse, IKnowledgeSet} from '~/types'


export const token =
    "eyJhbGciOiJIUzI1NiJ9.eyJ1c2VySWQiOjI3OCwiaWF0IjoxNzU0MTAxNzc4LCJleHAiOjE3ODU2Mzc3Nzh9.TvRIGX_8OsADd1joJ-C4s2zgWNCMuK7JnkySsyqtxj0"

export async function recommendRequest(
    pageNum: number,
    pageSize: number,
    categoryId: number
): Promise<IKnowledgeSet[]> {
    try {
        const config = useRuntimeConfig() // 获取 apiBase
        const res = await $fetch<DataResponse<IKnowledgeSet[]>>(
            `${config.public.apiBase}/knowledgeSet/recommendV3`,
            {
                method: 'GET',
                query: {pageNum, pageSize, categoryId},
                headers: {
                    Accept: 'application/json',
                    'Content-Type': 'application/json',
                    token: token,
                },
            }
        )

        if (res.code === 200) {
            return res.data
        } else {
            console.log(`recommendRequest failed:${res.msg}`)
            return []
        }
    } catch (e) {
        console.log(`recommendRequest exception:${e}`)
        return []
    }
}
